package com.hub.wc;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.AggregateOperator;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;
import scala.Int;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 批处理wordcount
 */
public class WordCount {


    public static void main(String[] args) throws Exception {

        // 创建执行环境
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        // 从文件读取数据
        String inputPath = "/usr/local/flink/txt/hello.txt";

        // 数据集
        DataSet<String> inputDataSet = env.readTextFile(inputPath);

        //
        DataSet<Tuple2<String, Integer>> output = inputDataSet
                                                .flatMap(new MyFlatMapFunction())
                                                .groupBy(0)
                                                .sum(1);

        output.print();
    }



}
